{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2dc835ad-2a82-4a28-8257-eebd8bd8b4e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "fi=open(\"三国演义-网络版.txt\",\"r\",encoding='utf-8')\n",
    "fo=open(\"三国演义-汉字统计.txt\",\"w\",encoding='utf-8')\n",
    "txt=fi.read()\n",
    "d={}\n",
    "for c in txt:\n",
    "    d[c]=d.get(c,0)+1\n",
    "del d[' ']\n",
    "del d['\\n']\n",
    "ls=[]\n",
    "for key in d:\n",
    "    ls.append(\"{}:{}\".format(key,d[key]))\n",
    "fo.write(\",\".join(ls))\n",
    "fi.close()\n",
    "fo.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a095ced4-4b0c-4c4f-99a5-e76460b7d896",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5bf58cbc-1e65-4e66-8801-3ee57df63d80",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
